home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / GSRC208A.ZIP / EDREACT.C < prev    next >
C/C++ Source or Header  |  1993-03-14  |  12KB  |  374 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*          GWTOP - Topology         */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*        Reactions dialog box       */
  14. /*                                   */
  15. /*           QuickC/WIN 1.0          */
  16. /*                                   */
  17. /*   (include here compilers that    */
  18. /*   compiled GWSIM successfully)    */
  19. /*                                   */
  20. /*************************************/
  21.  
  22.  
  23. #include <windows.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "defines.h"                    /* symbols also used in .DLG files        */
  27. #include "globals.h"                    /* gepasi's own symbols                    */
  28. #include "gwtop.h"                        /* macros, function prototypes, etc.    */
  29. #include "gep1.h"                        /* gepasi's variables                    */
  30. #include "topgvar.h"                    /* global variables                        */
  31. #include "strtbl.h"                        /* symbols for the string table            */
  32.  
  33. #pragma alloc_text( CODE2, ClearReactions, AddReactLst, EdReact )
  34.  
  35. void ClearReactions( void )
  36. {
  37.  int i, j;
  38.  
  39.  for( i=0; i<totmet; i++ )
  40.  {
  41.   metname[i][0] = '\0';
  42.   intmet[i] = 1;
  43.   for( j=0; j<nsteps; j++ )
  44.    stoiu[i*MAX_MET + j] = 0;
  45.  }
  46.  for( i=0; i<nsteps; i++ )
  47.   for( j=0; j<MAX_MOL; j++ )
  48.    (*rs)[i][j] = 0;
  49.  nsteps  = 0;
  50.  totmet  = 0;
  51. }
  52.  
  53.  
  54. void AddReactLst( HWND hControl, int j, int is_index, int scroll,
  55.                   int *totm, char (huge *metn)[NAME_L],
  56.                   int huge *sto, int *im, unsigned char *rev,
  57.                   int (huge *rs)[MAX_STEP][MAX_MOL] )
  58. {
  59.  int i, k, st, first, buffWidth, tempstoi[MAX_MET];
  60.  char auxstr[256], buff[256];
  61.  HANDLE hDC;
  62.  
  63.  *buff = '\0';
  64.  /* setup the stoicheiometries of the substrates                    */
  65.  for( i=0; i<*totm; i++ ) tempstoi[i] = 0;
  66.  for( i=0; i<MAX_MOL; i++ )
  67.   if ((*rs)[j][i]<0) tempstoi[ -(*rs)[j][i]-1 ]--;
  68.  for( k=0, first=1; k<MAX_MOL; k++ )
  69.  {
  70.   if ((*rs)[j][k]<0)
  71.   {
  72.    i = -(*rs)[j][k]-1;
  73.    st = tempstoi[i];
  74.    if( st < 0 )
  75.    {
  76.     if ( st == -1 )
  77.      wsprintf( auxstr, "%s%s", first==1 ? (LPSTR) "" : (LPSTR) " + ", &metn[i][0] );
  78.     else
  79.      wsprintf( auxstr, "%s%i*%s", first==1 ? (LPSTR) "" : (LPSTR) " + ", -st, &metn[i][0] );
  80.     _fstrcat( buff, auxstr );
  81.     first = 0;
  82.    }
  83.    for( ; (i == -(*rs)[j][k]-1) && (k<=MAX_MOL) ; k++);
  84.    k--;
  85.   }
  86.  }
  87.  if( rev[j] )                                            /* the connector        */
  88.   _fstrcat( buff, " = " );
  89.  else
  90.   _fstrcat( buff, " -> " );
  91.  
  92.  /* setup the stoicheiometries of the products                        */
  93.  for( i=0; i<*totm; i++ ) tempstoi[i] = 0;
  94.  for( i=0; i<MAX_MOL; i++ )
  95.   if ((*rs)[j][i]>0) tempstoi[ (*rs)[j][i]-1 ]++;
  96.  for( k=0, first=1; k<MAX_MOL; k++ )
  97.  {
  98.   if ((*rs)[j][k]>0)
  99.   {
  100.    i = (*rs)[j][k]-1;
  101.    st = tempstoi[i];
  102.    if( st > 0 )
  103.    {
  104.     if( st == 1 )
  105.      wsprintf( auxstr, "%s%s", first==1 ? (LPSTR) "" : (LPSTR) " + ", &metn[i][0] );
  106.     else
  107.      wsprintf( auxstr, "%s%i*%s", first==1 ? (LPSTR) "" : (LPSTR) " + ", st, &metn[i][0] );
  108.     _fstrcat( buff, auxstr );
  109.     first = 0;
  110.    }
  111.    for( ; (i == (*rs)[j][k]-1) && (k<=MAX_MOL) ; k++);
  112.    k--;
  113.   }
  114.  }
  115.  
  116.  hDC = GetDC( hControl );
  117.  buffWidth = 5 + LOWORD( GetTextExtent( hDC, buff, _fstrlen(buff) ) );
  118.  SetTextJustification( hDC, 0, 0 );
  119.  ReleaseDC( hControl, hDC );
  120.  if( buffWidth > lbWidth )
  121.  {
  122.   lbWidth = buffWidth;
  123.   SendMessage( hControl, LB_SETHORIZONTALEXTENT, lbWidth, (DWORD) 0 );
  124.  }
  125.  if( is_index )
  126.  {
  127.   SendMessage( hControl, LB_DELETESTRING, j, 0 );
  128.   SendMessage( hControl, LB_INSERTSTRING, j, (DWORD) (LPSTR) buff );
  129.  }
  130.  else
  131.   SendMessage( hControl, LB_INSERTSTRING, -1, (DWORD) (LPSTR) buff );
  132.  if( scroll ) SendMessage( hControl, WM_VSCROLL, SB_BOTTOM, 0 );
  133. }
  134.  
  135. /*
  136.   EdReact - dialog box procedure for TOP_PARSER dialog box
  137. */
  138.  
  139. BOOL FAR PASCAL EdReact( HWND hDlg, WORD message, WORD wParam, LONG lParam )
  140. {
  141.  static HWND   hEditBox, hReacLst, hStepNam;
  142.  char    buffer[256], buff2[256], step_name[NAME_L];
  143.  int     i, j, nr, rv;
  144.  static int idx;
  145.  
  146.  
  147.  switch( message )
  148.  {
  149.   case WM_INITDIALOG:                                   /*message: initialize dialog box        */
  150.  
  151.    lbWidth = 0;                                            /* set the width of the list box to 0    */
  152.    idx = -1;                                            /* set an invalid alteration index        */
  153.  
  154.    /* get handles to the controls                            */
  155.    hEditBox = GetDlgItem( hDlg, IDC_REACT );
  156.    hReacLst = GetDlgItem( hDlg, IDC_REACTLST );
  157.    hStepNam = GetDlgItem( hDlg, IDC_REACTNAM );
  158.  
  159.    /* setup the mirrors                                        */
  160.    _fmemcpy( (void __far *) metn,
  161.                 (void __far *) metname,
  162.                 (size_t) MAX_MET * NAME_L * sizeof( char ) );
  163.    _fmemcpy( (void __far *) stepn,
  164.                 (void __far *) stepname,
  165.                 (size_t) MAX_STEP * NAME_L * sizeof( char ) );
  166.    _fmemcpy( (void __far *) sto,
  167.                 (void __far *) stoiu,
  168.              (size_t) MAX_MET * MAX_STEP * sizeof( int ) );
  169.    _fmemcpy( (void __far *) lp,
  170.                 (void __far *) loop,
  171.              (size_t) MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  172.    _fmemcpy( (void __far *) intm,
  173.                 (void __far *) intmet,
  174.                 (size_t) MAX_MET * sizeof( int ) );
  175.    _fmemcpy( (void __far *) kinet,
  176.                 (void __far *) kinetu,
  177.              (size_t) MAX_STEP * sizeof( int ) );
  178.    _fmemcpy( (void __far *) nmd,
  179.               (void __far *) nmod,
  180.              (size_t) MAX_STEP * sizeof( unsigned char ) );
  181.    _fmemcpy( (void __far *) rvr,
  182.               (void __far *) revers,
  183.              (size_t) MAX_STEP * sizeof( unsigned char ) );
  184.    _fmemcpy( (void __far *) rs,
  185.               (void __far *) rstr,
  186.              (size_t) MAX_STEP * MAX_MOL * sizeof( int ) );
  187.    nst = nsteps;
  188.    totm = totmet;
  189.    nlps = nloops;
  190.    kass = kinass;
  191.    lass = loopass;
  192.  
  193.    /* add all steps to the list box                                        */
  194.    for( j=0; j<nst; j++ ) AddReactLst( hReacLst, j, 1, (j==nst), &totm, metn, sto, intm, rvr, rs );
  195.  
  196.    /* write the name of the new reaction in the name edit box            */
  197.    wsprintf( (LPSTR) step_name, "R%d", nst+1 );
  198.    SendMessage( hStepNam, WM_SETTEXT, 0, (DWORD) (LPSTR) step_name );
  199.  
  200.    return( TRUE );
  201.  
  202.   case WM_COMMAND:
  203.    switch( wParam )
  204.    {
  205.     case IDC_ADD:
  206.      SendMessage( hEditBox, WM_GETTEXT, 256, (DWORD) (LPSTR) buffer );
  207.      if( idx == -1 )                                    /* new item        */
  208.      {
  209.       /* verify if we reached the maximum number of steps                */
  210.       if( nst == MAX_STEP )
  211.       {
  212.        LoadString(hInst, IDS_ERR_STEP_EXCEED, szString, sizeof(szString));
  213.        MessageBeep( MB_OK );
  214.        MessageBox(NULL, szString, NULL, MB_ICONINFORMATION);
  215.        return( TRUE );
  216.       }
  217.       /* if not assign the next step number to this one                    */
  218.       j = nst;
  219.      }
  220.      else j = idx;                                        /* alterion        */
  221.      rv = reaction( buffer, j, &totm, metn, sto, rs, intm, rvr );
  222.      if( rv == -2 )
  223.      {
  224.       LoadString(hInst, IDS_ERR_MET_EXCEED, szString, sizeof(szString));
  225.       MessageBeep( MB_OK );
  226.       MessageBox(NULL, szString, NULL, MB_ICONINFORMATION);
  227.       return( TRUE );
  228.      }
  229.      if( rv == 0 )
  230.      {
  231.       SendMessage( hStepNam, WM_GETTEXT, NAME_L, (DWORD) (LPSTR) stepn[j] );
  232.       AddReactLst( hReacLst, j, 1, (j==nst), &totm, metn, sto, intm, rvr, rs );
  233.       if ( idx == -1 ) nst++;
  234.       else
  235.       {
  236.        idx = -1;                                /* reset idx            */
  237.        if( ktype[kinet[j]].nmodf>0 )            /* if there were modfs    */
  238.        {
  239.         nlps--;
  240.         for(i=0;i<MAX_MET;i++) (*lp)[j][i] = 0;    /* reset row of loop    */
  241.         if( ktype[kinet[j]].nmodf == nmd[j] ) lass--;    /* decrease lass                */
  242.        }
  243.        if( kinet[j] != NOT ) kass --;
  244.        kinet[j] = 0;                            /* reset kinetic type    */
  245.       }
  246.       /* clear the reaction edit box                                    */
  247.       SetWindowText( hEditBox, (LPSTR) "" );
  248.       /* write the name of the new reaction in the name edit box        */
  249.       wsprintf( (LPSTR) step_name, "R%d", nst+1 );
  250.       SendMessage( hStepNam, WM_SETTEXT, 0, (DWORD) (LPSTR) step_name );
  251.      }
  252.      else
  253.      {
  254.       LoadString(hInst, IDS_ERR_SYNTAX, szString, sizeof(szString));